$(function () {
    $("#page").load("/back/page.html");
    findAll();
});
function newAdd() {
    $('#right').load('/back/nav/navAdd.html')
}
function findAll() {
    let data = {};
    data.id = $("#id").val();
    data.name = $("#name").val();
    data.pageSize = $.trim($("#pageSize").val());
    data.pageNum = $.trim($("#pageNum").val());
    data.token=$.cookie("token");
    let result = myAjax('/back/order/findAllNav', 'get', data);
    showNavs(result.list);
    $("#pageCount").html(result.number);
}

function showNavs(data) {
    let html = "";//定一个一个空得html
    for (let i = 0; i < data.length; i++) {
        html += '  <tr>\n' +
            '        <td>' + data[i].id + '</td>\n' +
            '        <td>' + data[i].name + '</td>\n' +
            '        <td>' + data[i].href + '</td>\n' +
            '   <td><a  href="javascript:edit( ' + data[i].id + ')">编辑</a> <a  href="javascript:dele( ' + data[i].id + ')">删除</a></td>\n' +
            '    </tr>';
    }
    $("#navFindAll").html(html);//赋值
}

function edit(id) {
    localStorage.setItem("navId", id);
    //sessionStorage.setItem("id",id);   本地存储  两种方式都可以
    $('#right').load('/back/nav/navEdit.html');//页面跳转
}

function dele(id) {
    let result = myAjax('/back/nav/delete', 'get', {id: id,token:$.cookie("token")});
    if (result.result === 1) {
        $("#right").load('/back/nav/navManage.html');
    } else {
        alert("删除失败")
    }
}